using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class JobMap : EntityTypeConfiguration<Job>
    {
        public JobMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.JOBNO)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.DESC)
                .IsRequired()
                .HasMaxLength(25);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Jobs");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.JOBNO).HasColumnName("JOBNO");
            this.Property(t => t.DESC).HasColumnName("DESC");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.CURRENCY).HasColumnName("CURRENCY");
            this.Property(t => t.CostTypeId).HasColumnName("CostTypeId");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.EstExpenses).HasColumnName("EstExpenses");
            this.Property(t => t.EstRevenues).HasColumnName("EstRevenues");
            this.Property(t => t.PercentComplete).HasColumnName("PercentComplete");
            this.Property(t => t.Project).HasColumnName("Project");
            this.Property(t => t.Inactive).HasColumnName("Inactive");

            // Relationships
            this.HasRequired(t => t.CostType)
                .WithMany(t => t.Jobs)
                .HasForeignKey(d => d.CostTypeId);
            this.HasRequired(t => t.Project1)
                .WithMany(t => t.Jobs)
                .HasForeignKey(d => d.Project);

        }
    }
}
